@echo off
echo ========================================
echo    Cencat SaaS Multi-Module Startup Script
echo    @author cencat
echo    @since 2024-01-01
echo ========================================
echo.

echo Starting Cencat SaaS modules...
echo.

echo Step 1: Compiling the project...
call mvn clean compile -DskipTests
if %errorlevel% neq 0 (
    echo Project compilation failed!
    pause
    exit /b 1
)
echo Project compiled successfully!
echo.

echo Step 2: Packaging the project...
call mvn clean package -DskipTests
if %errorlevel% neq 0 (
    echo Project packaging failed!
    pause
    exit /b 1
)
echo Project packaged successfully!
echo.

echo Step 3: Starting modules...
echo.

echo Startup order:
echo    1. cencat-order   (Order Module) - Port: 8081
echo    2. cencat-product (Product Module) - Port: 8082  
echo    3. cencat-merchant(Merchant Module) - Port: 8083
echo    4. cencat-user    (User Module) - Port: 8084
echo.

echo Starting cencat-order module...
start "Cencat Order Module" cmd /k "cd /d %~dp0cencat-order && mvn spring-boot:run"
echo cencat-order module starting... (Port: 8081)
echo    API Docs: http://localhost:8081/order/swagger-ui/index.html
echo    Health Check: http://localhost:8081/order/actuator/health
echo.

timeout /t 10 /nobreak >nul

echo Starting cencat-product module...
start "Cencat Product Module" cmd /k "cd /d %~dp0cencat-product && mvn spring-boot:run"
echo cencat-product module starting... (Port: 8082)
echo    API Docs: http://localhost:8082/product/swagger-ui/index.html
echo    Health Check: http://localhost:8082/product/actuator/health
echo.

timeout /t 10 /nobreak >nul

echo Starting cencat-merchant module...
start "Cencat Merchant Module" cmd /k "cd /d %~dp0cencat-merchant && mvn spring-boot:run"
echo cencat-merchant module starting... (Port: 8083)
echo    API Docs: http://localhost:8083/merchant/swagger-ui/index.html
echo    Health Check: http://localhost:8083/merchant/actuator/health
echo.

timeout /t 10 /nobreak >nul

echo Starting cencat-user module...
start "Cencat User Module" cmd /k "cd /d %~dp0cencat-user && mvn spring-boot:run"
echo cencat-user module starting... (Port: 8084)
echo    API Docs: http://localhost:8084/user/swagger-ui/index.html
echo    Health Check: http://localhost:8084/user/actuator/health
echo.

echo ========================================
echo All modules startup completed!
echo ========================================
echo.
echo Module Access URLs:
echo    Order Module: http://localhost:8081/order/
echo    Product Module: http://localhost:8082/product/
echo    Merchant Module: http://localhost:8083/merchant/
echo    User Module: http://localhost:8084/user/
echo.
echo API Documentation URLs:
echo    Order API: http://localhost:8081/order/swagger-ui/index.html
echo    Product API: http://localhost:8082/product/swagger-ui/index.html
echo    Merchant API: http://localhost:8083/merchant/swagger-ui/index.html
echo    User API: http://localhost:8084/user/swagger-ui/index.html
echo.
echo Health Check URLs:
echo    Order Health: http://localhost:8081/order/actuator/health
echo    Product Health: http://localhost:8082/product/actuator/health
echo    Merchant Health: http://localhost:8083/merchant/actuator/health
echo    User Health: http://localhost:8084/user/actuator/health
echo.
echo Important Notes:
echo    1. Make sure MySQL is running (Port: 3306)
echo    2. Make sure Redis is running (Port: 6379)
echo    3. Database name: cencat_saas
echo    4. Database user: root, password: 123456
echo    5. Modules need time to start, please wait patiently
echo    6. Check if ports are available if startup fails
echo.
echo To stop modules:
echo    Press Ctrl+C in each module window
echo.
echo Technical Support:
echo    Developer: cencat
echo    Email: cencat@example.com
echo.
echo ========================================
echo Cencat SaaS System Ready!
echo ========================================
echo.
pause